home *** CD-ROM | disk | FTP | other *** search
- /* FLU.KB
- (See end of file for 'HOW TO RUN' info)
-
- Elementary (rule-based) medical diagnosis.
- The purpose of this file is to get you used to
- the rule notation. More sophisticated diagnosis
- would ordinarily use MIKE's frame system.
-
- Example symptom descriptors might be as follows
-
- Alice has a dry throat, a muzzy feeling in the head, a runny nose, sneezing
- and a slight transient fever, i.e. nothing worse than the common cold. In
- MIKE list style syntax this would look like the following :
-
- [alice, has, dry_throat]
- [alice, has, muzzy_feeling_head]
- [alice, has, runny_nose]
- [alice, is, sneezing]
- [alice, has, slight_transient_fever]
-
- Bert has a blocked and runny nose, he is sneezing, and his eyes are red,
- itchey, and watering. Bert is thus a hay-fever sufferer. The MIKE for the
- following is listed below.
-
- [bert, has, runny_nose]
- [bert, has, blocked_nose]
- [bert, is, sneezing]
- [bert, has, red_itchy_watery_eyes]
-
- Another sufferer of the common cold in Charlie. He has a dry throat, a
- muzzy feeling in the head, a runny nose and sneezing, and has a slight
- transient fever. A MIKE version follows.
-
- [charlie, has, dry_throat]
- [charlie, has, muzzy_feeling_head]
- [charlie, has, runny_nose]
- [charlie, is, sneezing]
- [charlie, has, slight_transient_fever]
-
- Poor Donna's got laryngitis. Her symptoms are a persistent dry cough, a
- hoarse voice, laryngeal discomfort, slight transient fever, and malaise.
- A MIKE version follows:-
-
- [donna, has, persistent_dry_cough]
- [donna, has, hoarse_voice]
- [donna, has, laryngeal_discomfort]
- [donna, has, slight_transient_fever]
- [donna, has, malaise]
-
- Eva has influenza. She has a persistent dry cough, a sore throat, slight
- transient fever, shivering, malaise, a headache, and is suffering from diffuse
- aches and pains.
-
- [eva, has, persistent_dry_cough]
- [eva, has, sore_throat]
- [eva, has, slight_transient_fever]
- [eva, is, shivering]
- [eva, has, malaise]
- [eva, has, headache]
- [eva, has, aches_and_pains]
-
- Finally Frank has seasonal allergic rhinitis, better known as hay fever.
- He has a runny nose, a blocked nose, sneezing, and soar red eyes.
-
- [frank, has, runny_nose]
- [frank, has, blocked_nose]
- [frank, is, sneezing]
- [frank, has, red_itchy_watery_eyes].
-
- To 'seed' working memory with the above facts, you would need to use
- 'add'. For example:
-
- ?- add [frank, has, runny_nose].
- ?- add [frank, has, blocked_nose].
-
- Alternatively, the appropriate facts could be added as part of the
- right-hand side of your very first rule, e.g.
- rule init forward
- if
- start
- then
- add [frank, has, runny_nose] &
- add [frank, has, blocked_nose] &
- add [frank, is, sneezing] &
- add [frank, has, red_itchy_watery_eyes].
-
- We adopt the latter solution, as the following rule base shows:
- */
-
-
- /* =============== diagnosis rule base ================== */
-
- rule patient_initialisation_Rule forward
- if
- start /* special symbol always in wm at first */
- then
- remove start & /* get rid of special symbol */
- add [alice, has, dry_throat] &
- add [alice, has, muzzy_feeling_head] &
- add [alice, has, runny_nose] &
- add [alice, is, sneezing] &
- add [alice, has, slight_transient_fever] &
- add [bert, has, runny_nose] &
- add [bert, has, blocked_nose] &
- add [bert, is, sneezing] &
- add [bert, has, red_itchy_watery_eyes] &
- add [charlie, has, dry_throat] &
- add [charlie, has, muzzy_feeling_head] &
- add [charlie, has, runny_nose] &
- add [charlie, is, sneezing] &
- add [charlie, has, slight_transient_fever] &
- add [donna, has, persistent_dry_cough] &
- add [donna, has, hoarse_voice] &
- add [donna, has, laryngeal_discomfort] &
- add [donna, has, slight_transient_fever] &
- add [donna, has, malaise] &
- add [eva, has, persistent_dry_cough] &
- add [eva, has, sore_throat] &
- add [eva, has, slight_transient_fever] &
- add [eva, is, shivering] &
- add [eva, has, malaise] &
- add [eva, has, headache] &
- add [eva, has, aches_and_pains] &
- add [frank, has, runny_nose] &
- add [frank, has, blocked_nose] &
- add [frank, is, sneezing] &
- add [frank, has, red_itchy_watery_eyes] &
- add diagnosing.
-
-
- rule 1 forward
- if [Patient, has, runny_nose] &
- [Patient, has, blocked_nose] &
- [Patient, is, sneezing] &
- [Patient, has, red_itchy_watery_eyes]
- then
- add [Patient, has, hay_fever] & /* optional addition to working memory */
- announce [Patient, ' has hay fever.'].
-
- rule 2 forward
- if [Patient, has, persistent_dry_cough] &
- [Patient, has, hoarse_voice] &
- [Patient, has, laryngeal_discomfort] &
- [Patient, has, slight_transient_fever] &
- [Patient, has, malaise]
- then
- add [Patient, has, laryngitis] &
- announce [Patient, ' has laryngitis.'].
-
- rule 3 forward
- if [Patient, has, dry_throat] &
- [Patient, has, muzzy_feeling_head] &
- [Patient, has, runny_nose] &
- [Patient, is, sneezing] &
- [Patient, has, slight_transient_fever]
- then
- add [Patient, has, a, common_cold] &
- announce [Patient, ' has a common cold.'].
-
-
- rule 4 forward
- if [Patient, has, persistent_dry_cough] &
- [Patient, has, sore_throat] &
- [Patient, has, slight_transient_fever] &
- [Patient, is, shivering] &
- [Patient, has, malaise] &
- [Patient, has, headache] &
- [Patient, has, aches_and_pains]
- then
- add [Patient, has, influenza] &
- announce [Patient, ' has influenza.'].
-
- rule stop forward
- if
- diagnosing /* least specific rule, so will fire last of all */
- then
- remove diagnosing &
- announce [nl,'All possible diagnoses have been found',nl,
- 'Diagnosis complete. BYE! ',nl] &
- halt.
-
- /* HOW TO RUN THIS EXAMPLE
- after loading the above rules, (using ?- kb 'flu.kb'.)
- simply invoke the forward-chainer via
- ?- fc.
-
- The contents of working memory can be viewed at the end via
- ?- show wm.
-
- Dynamic viewing of working memory changes can be observed
- by toggling on tracing option number 5 as follows:
- ?- tracing(5).
-
- Finally, if you want to see how a conclusion was reached, use 'how',
- e.g.:
- ?- how [frank, has, hay_fever].
- */